from configparser import ConfigParser
from pathlib import Path
import pandas as pd

def get_config_from(file_path: Path):
    conf = ConfigParser()
    
    conf.read(file_path)
    
    return conf.getfloat('config', 'qos_constraint'), conf.getint('config', 'base_cost')

def get_data_from(file_path: Path):
    return pd.read_csv(file_path)

def get_ans_from(file_path: Path):
    try:
        with open(file_path, 'r') as f:
            raw = f.read().splitlines()
            output = [(j.split(':')[0], {i.split(',')[0]: set(i.split(',')[1:]) for i in j.split(":")[1][1:-1].split('>,<')} if j[-1] != ':' else None) for j in raw]
    except:
        raise ValueError('answer file has wrong format.')
    return output